﻿using System;
using SailHero.Soft.ESB.Collections;
using SailHero.Soft.ESB.Communication.ClientAndServer.Communication.Protocols;

namespace SailHero.Soft.ESB.Communication.ClientAndServer.Server
{
    /// <summary>
    /// Represents a SailHero.Soft.ESB server that is used to accept and manage client connections.
    /// </summary>
    public interface IServer
    {
        /// <summary>
        /// This event is raised when a new client connected to the server.
        /// </summary>
        event EventHandler<ServerClientEventArgs> ClientConnected;

        /// <summary>
        /// This event is raised when a client disconnected from the server.
        /// </summary>
        event EventHandler<ServerClientEventArgs> ClientDisconnected;

        /// <summary>
        /// Gets/sets wire protocol factory to create IWireProtocol objects.
        /// </summary>
        IWireProtocolFactory WireProtocolFactory { get; set; }

        /// <summary>
        /// A collection of clients that are connected to the server.
        /// </summary>
        ThreadSafeSortedList<string, IServerClient> Clients { get; }
        
        /// <summary>
        /// Starts the server.
        /// </summary>
        void Start();

        /// <summary>
        /// Stops the server.
        /// </summary>
        void Stop();

        /// <summary>
        /// server IsRuning ?.
        /// </summary>
        /// <returns>server IsRuning</returns>
        bool IsRuning();



        /// <summary>
        /// 登录超时时间，以分钟为单位，
        /// 按照协议需要两次来完成，
        /// 例如：30分钟超时，就需要每隔15分钟进行一次登录，、
        /// 超过2次视为超时
        /// </summary>
        int LoginTimeOut { set; get; }

    }
}
